package com.cal.utms.valuation;

import java.util.Date;

import com.cal.utms.entity.Deal;

public class ReverseRepoCalculator {
	
	private double withholdingTax;
	private double maturityValue;
	private double effectiveRate;
	private double tenor;
	private double dayCount = 365;

	//Eod Params
	private double dailyInterest;
	private double marketValueCpa;
	private int daysInInterest;
	
	
	public void valuateAllParameters(Deal deal){
		double principleValue = deal.getDealValue().doubleValue();
		double actualRate = deal.getActualRate().doubleValue();
		String dayCountInput = deal.getDayBasis();
		Date valueDate = deal.getValueDate();
		Date maturityDate = deal.getMaturityDate();

		valuateAllParameters(principleValue, actualRate, dayCountInput, valueDate, maturityDate);
	}
	
	public void valuateEodParams(Deal deal, Date valueDate){
		valuateAllParameters(deal);
		daysInInterest = ((int)((valueDate.getTime() - deal.getValueDate().getTime())/(1000 * 60 * 60 * 24)))+1;
		dailyInterest = deal.getDealValue().doubleValue()*(effectiveRate/100)/dayCount;
		marketValueCpa = deal.getDealValue().doubleValue() + deal.getDealValue().doubleValue()*(effectiveRate/100)*((double)daysInInterest/(double)dayCount);
	}
	
	public void valuateAllParameters(final double principleValue, double actualRate, String dayCountInput, final Date valueDate, Date maturityDate){
		effectiveRate = actualRate; //Repos Does not have Withholding Tax
		withholdingTax = 0;
		tenor = (maturityDate.getTime() - valueDate.getTime())/(1000 * 60 * 60 * 24);
		actualRate = actualRate/100;
		if(dayCountInput.equals("Act / 360")){
			dayCount = 360;
		}else if(dayCountInput.equals("Act / 364")){
			dayCount = 364;
		}else if(dayCountInput.equals("30 / 360")){
			dayCount = 360;
		}
		System.out.println("DayBAsis:"+dayCount);
		valuate(principleValue, actualRate, dayCount, tenor);
		
	}
	
	public void valuate(double principleValue, double actualRate, double dayBasis, double tenor){
			maturityValue = principleValue + principleValue*actualRate*(tenor/dayBasis);
			System.out.println("MatVal:"+maturityValue);
	}

	public double getMaturityValue() {
		return maturityValue;
	}
	public void setMaturityValue(double maturityValue) {
		this.maturityValue = maturityValue;
	}

	public double getTenor() {
		return tenor;
	}

	public void setTenor(double tenor) {
		this.tenor = tenor;
	}

	public double getDayCount() {
		return dayCount;
	}

	public void setDayCount(double dayCount) {
		this.dayCount = dayCount;
	}

	public double getDailyInterest() {
		return dailyInterest;
	}

	public void setDailyInterest(double dailyInterest) {
		this.dailyInterest = dailyInterest;
	}

	public double getMarketValueCpa() {
		return marketValueCpa;
	}

	public void setMarketValueCpa(double marketValueCpa) {
		this.marketValueCpa = marketValueCpa;
	}

	public int getDaysInInterest() {
		return daysInInterest;
	}

	public void setDaysInInterest(int daysInInterest) {
		this.daysInInterest = daysInInterest;
	}

	public double getWithholdingTax() {
		return withholdingTax;
	}

	public void setWithholdingTax(double withholdingTax) {
		this.withholdingTax = withholdingTax;
	}

	public double getEffectiveRate() {
		return effectiveRate;
	}

	public void setEffectiveRate(double effectiveRate) {
		this.effectiveRate = effectiveRate;
	}
	

}
